A Tcl/Tk Tool for Aiding Internationalization Support in Qt-Based Applications

by

Csaba Nemethi

csaba.nemethi@t-online.de

Contents

  1. Abstract
  2. Overview of Qt's Internationalization Support
  3. Problems Related to Managing the Translation Files
  4. The TransCheck Application
  5. A Few Code Snippets

1. Abstract

The talk is about a Tcl/Tk application developed by the author for a big international radiocommunication company.  A great part of the software being developed at that company uses the multi-platform GUI framework Qt, which has, among others, a good multi-platform support.  The Tcl/Tk tool presented in the talk has proved invaluable for keeping the translations consistent and managing the translation process for a variety of European and Asian languages.


2. Overview of Qt's Internationalization Support

Main features:

Rules for translation-aware coding:

Rules for the development and deployment:

  1. Write the code as described above.
  2. For each project ProjectName making up the application:  Run the Qt command line tool lupdate to extract the translatable strings from the source project's source files as well as its UI description (.ui) files into translation source files having names like ProjectName_de.ts, ProjectName_fr.ts, etc.
  3. Translate the texts contained in the translation source files or let them translated into the languages supported by the application, with the aid of the Qt Linguist application.
  4. Run the Qt command line tool lrelease to generate binary Qt message .qm files from the translated .ts files.  It is common practice to convert several .ts files to one and the same .qm file, placed into the translations subdirectory of the directory containing the executable and its DLLs.
  5. Repeat the steps 2 - 4 above as often as necessaray.
  6. For each locale supported by the application:  Copy the Qt libraries' binary translation file (qt_de.qm, qt_fr.qm, etc.) bundled with the Qt distribution into the translations subdirectory mentioned above.
  7. Immediately after starting the application, load the binary translation files corresponding to the default locale, with the aid of corresponding QTranslator class objects.  Repeat this action for any of the supported languages whenever the user selects another one.
  8. Make sure the contents of the above-mentioned translations subdirectory will be distributed and installed together with the application.

3. Problems Related to Managing the Translation Files

A few basic requirements:

How to fulfill them?

Fulfilling these requirements by using Qt Linguist only is nearly impossible.  Typical middle-size software has about 10,000 texts to be translated, quite often contained in about 100 translation files, which in turn are to be processed by one or more translators for each language supported by the application(s).

4. The TransCheck Application

The Tcl/Tk tool TransCheck, developed recently by the author for a big radiocommunication company, has proved to be of great help in mastering the above-mentioned requirements and managing the translation process.

Live presentation ...

Contents of the starpack:


5. A Few Code Snippets

Creating and configuring the tablelist widget:

tablelist::tablelist $tbl \
    -columns {
      64 "Source Text"
      64 "Translated Text"
      0 "Project"
      0 "Context"
    } \
    -activestyle frame -background white -borderwidth 0 -showseparators yes \
    -spacing 1 -width 200 -height 40 -movablecolumns yes -stretch all \
    -labelcommand tablelist::sortByColumn \
    -labelcommand2 tablelist::addToSortColumns \
    -tooltipaddcommand tooltipAddCmd -tooltipdelcommand tooltipDelCmd \
    -xscrollcommand [list $hsb set] -yscrollcommand [list $vsb set]
if {$::tcl_platform(osVersion) < 6.0} {                   ;# Windows XP
  $tbl configure -stripebackground #e8e8e8
} else {                                                  ;# Windows Vista/7
  $tbl configure -stripebackground #f6f6f6
}

Configuring the columns:

$tbl columnconfigure 0 -name "srcText" -sortmode asciinocase -wrap yes
$tbl columnconfigure 1 -name "trText"  -sortmode asciinocase -wrap yes
$tbl columnconfigure 2 -name "project" -sortmode asciinocase -maxwidth 32 \
    -changesnipside yes
$tbl columnconfigure 3 -name "context" -sortmode asciinocase -maxwidth 32 \
    -changesnipside yes

Tooltip support:

proc tooltipAddCmd {tbl row col} {
  if {($row >= 0 && [$tbl iselemsnipped $row,$col fullText]) ||
      ($row <  0 && [$tbl istitlesnipped $col fullText])} {
    tooltip::tooltip $tbl $fullText
  }
}

proc tooltipDelCmd tbl {
  tooltip::tooltip $tbl ""
}

Setting a filter:

set rowCount [$tbl size]
for {set row 0} {$row < $rowCount} {incr row} {
  $tbl rowconfigure $row -hide 1
}

set searchCmd [list $tbl searchcolumn $col $pattern -all -glob]
if {!$caseSens} {
  lappend searchCmd -nocase
}
. . .

set rowList [eval $searchCmd]
foreach row $rowList {
  $tbl rowconfigure $row -hide 0
}